import java.util.Arrays;
import java.util.Scanner;

public class TestDemo {

    //    写一个递归方法，输入一个非负整数，返回组成它的数字之和
    public static int sumEvery(int n) {
        if (n < 10) {
            return n;
        }
        int tmp = n % 10 + sumEvery(n / 10);
        return tmp;
    }

    public static void main1(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int sum = sumEvery(n);
        System.out.println(sum);
    }

    public static int fib(int n) {
        if (n == 1 || n == 2) {
            return 1;
        }
        int tmp = fib(n - 1) + fib(n - 2);
        return tmp;
    }

    public static void main2(String[] args) {
//        递归求斐波那契数列的第 N 项
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int temp = fib(n);
        System.out.println("第" + n + "项斐波那契数列为" + temp);
    }

    public static void print(int n) {
        if (n < 10) {
            System.out.println(n);
        } else {
            print(n / 10);
            System.out.println(n % 10);
        }
    }

    public static void main3(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        print(n);
    }

    public static int sum(int n) {
        if (n == 1) {
            return 1;
        } else {
            int tmp = n + sum(n - 1);
            return tmp;
        }
    }

    public static void main4(String[] args) {
//        递归求和
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int ret = sum(n);
        System.out.println(ret);
    }

    public static int fac(int n) {
        if (n == 1) {
            return 1;
        } else {
            int tmp = n * fac(n - 1);
            return tmp;
        }
    }

    public static void main5(String[] args) {
//        递归求n的阶乘
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int ret = fac(n);
        System.out.println(ret);
    }

    public static void main6(String[] args) {
//        数组
        int[] array = {1, 2, 3, 4, 5};
        int[] array2 = new int[]{1, 2, 3, 4, 5};
        int[] array3 = new int[5];
//        System.out.println(array);  //在引用变量array中存放了对象的地址: [I@1b6d3586
    }

    public static void main7(String[] args) {
//        打印数组
        int[] array = {1, 2, 3, 4, 5};
//        1.for
//        for (int i = 0; i < array.length; i++) {
//            System.out.print(array[i]+" ");
//        }
//        2.foreach
//        for (int x: array) {
//            System.out.print(x+" ");
//        }
//        3.Array.toString
        String ret = Arrays.toString(array);
        System.out.println(ret);////将你传进来的数组，以字符串的形式进行输出 :[1, 2, 3, 4, 5]
    }

    public static void main8(String[] args) {
        int[] array = {1,2,3,4,5};
        array[0]=100;
        array[1]=200;
        String ret = Arrays.toString(array);
        System.out.println(ret);
    }

//    发现在func方法中修改形参 x 的值, 不影响实参的 num 值
    public static void func(int x) {
        x = 10;
        System.out.println("x = "+ x);
    }
    public static void main9(String[] args) {
        int num = 0;
        func(num);
        System.out.println("num = "+ num);
    }

//    发现在func方法内部修改数组的内容, 方法外部的数组内容也发生改变.
//因为数组是引用类型，按照引用类型来进行传递，是可以修改其中存放的内容的。
    public static void func1(int[] arr) {
        arr[0]=10;
        System.out.println("arr[0] = "+ arr[0]);
    }
    public static void main(String[] args) {
        int[] array = {1,2,3,4};
        func1(array);
        System.out.println("array[0] = "+ array[0]);
    }
}
